﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using System.Data;
using AspNetCs.Model;

namespace AspNetCs.SQLServerDAL
{
    public class Guest_DAL:IGuest
    {
        public DataTable getGuestList()
        {
            DataTable dataTable = new DataTable();
            string cmdText = "";
            return dataTable;
        }

        /// <summary>
        /// 通过留言编号查询留言内容
        /// </summary>
        /// <param name="guestId">留言编号</param>
        /// <returns></returns>
        public DataTable getGuestInfoByGuestId(int guestId)
        {
            DataTable dataTable = new DataTable();
            db.ParameterArry[] paras = new db.ParameterArry[1];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@GuestId";
            paras[0].objValue = guestId;
            
            string cmdText = "select *from Guest where GuestId=@GuestId";
            db dbOperate = new db();
            dataTable = dbOperate.GetSql_DataTable(cmdText,paras);
            return dataTable;
        }

        /// <summary>
        /// 通过留言编号删除留言
        /// </summary>
        /// <param name="guestId"></param>
        /// <returns></returns>
        public int deleteGuestByGuestId(int guestId)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[1];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@GuestId";
            paras[0].objValue = guestId;

            string cmdText = "delete from Guest where GuestId=@GuestId";
            db dbOperate = new db();
            count = dbOperate.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 审核或者取消审核
        /// </summary>
        /// <param name="guestId"></param>
        /// <param name="passOrNoPass"></param>
        /// <returns></returns>
        public int checkPass(int guestId, int passOrNoPass)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@GuestId";
            paras[0].objValue = guestId;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@IsPassed";
            paras[1].objValue = passOrNoPass;

            string cmdText = "update  Guest set IsPassed=@IsPassed  where GuestId=@GuestId";
            db dbOperate = new db();
            count = dbOperate.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 管理回复
        /// </summary>
        /// <param name="guestId"></param>
        /// <param name="replyContent"></param>
        /// <param name="addTime"></param>
        /// <returns></returns>
        public int addReply(int guestId, string replyContent, DateTime addTime)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[3];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@GuestId";
            paras[0].objValue = guestId;

            paras[1].dbType = SqlDbType.VarChar;
            paras[1].parName = "@AdminReply";
            paras[1].objValue = replyContent;

            paras[2].dbType = SqlDbType.DateTime;
            paras[2].parName = "@AdminReplyTime";
            paras[2].objValue = addTime;

            string cmdText = "update  Guest set AdminReply=@AdminReply,AdminReplyTime=@AdminReplyTime  where GuestId=@GuestId";
            db dbOperate = new db();
            count = dbOperate.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 用户发表留言
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int addGuest(Guest_Model model)
        {

            model.AdminReply = "";
            model.AdminReplyTime = DateTime.Now;

            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[18];

            paras[0].dbType = SqlDbType.VarChar;
            paras[0].parName = "@GuestName";
            paras[0].objValue = model.GuestName;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@GuestSex";
            paras[1].objValue = model.GuestSex;

            paras[2].dbType = SqlDbType.VarChar;
            paras[2].parName = "@GuestQQ";
            paras[2].objValue = model.GuestQQ;

            paras[3].dbType = SqlDbType.VarChar;
            paras[3].parName = "@GuestMsn";
            paras[3].objValue = model.GuestMsn;

            paras[4].dbType = SqlDbType.VarChar;
            paras[4].parName = "@GuestEmail";
            paras[4].objValue = model.GuestEmail;


            paras[5].dbType = SqlDbType.Text;
            paras[5].parName = "@GuestWebPage";
            paras[5].objValue = model.GuestWebPage;

            paras[6].dbType = SqlDbType.VarChar;
            paras[6].parName = "@GuestFeel";
            paras[6].objValue = model.GuestFeel;

            paras[7].dbType = SqlDbType.VarChar;
            paras[7].parName = "@GuestHeadPortrait";
            paras[7].objValue = model.GuestHeadPortrait;

            paras[8].dbType = SqlDbType.VarChar;
            paras[8].parName = "@GuestIP";
            paras[8].objValue = model.GuestIP;

            paras[9].dbType = SqlDbType.VarChar;
            paras[9].parName = "@GuestTitle";
            paras[9].objValue = model.GuestTitle;

            paras[10].dbType = SqlDbType.Text;
            paras[10].parName = "@GuestContent";
            paras[10].objValue = model.GuestContent;

            paras[11].dbType = SqlDbType.DateTime;
            paras[11].parName = "@GuestTime";
            paras[11].objValue = model.GuestTime;

            paras[12].dbType = SqlDbType.Text;
            paras[12].parName = "@AdminReply";
            paras[12].objValue = model.AdminReply;

            paras[13].dbType = SqlDbType.DateTime;
            paras[13].parName = "@AdminReplyTime";
            paras[13].objValue = model.AdminReplyTime;

            paras[14].dbType = SqlDbType.Int;
            paras[14].parName = "@IsPassed";
            paras[14].objValue = model.IsPassed;


            paras[15].dbType = SqlDbType.Int;
            paras[15].parName = "@IsPrivate";
            paras[15].objValue = model.IsPrivate;

            paras[16].dbType = SqlDbType.Int;
            paras[16].parName = "@IsDl";
            paras[16].objValue = model.IsDl;

            paras[17].dbType = SqlDbType.Int;
            paras[17].parName = "@IsUser";
            paras[17].objValue = model.IsUser;

            string cmdText = "insert into Guest values (@GuestName,@GuestSex,@GuestQQ,@GuestMsn,@GuestEmail,@GuestWebPage,@GuestFeel,@GuestHeadPortrait,@GuestIP,@GuestTitle,@GuestContent,@GuestTime,@AdminReply,@AdminReplyTime,@IsPassed,@IsPrivate,@IsDl,@IsUser)";
            db dbOperate = new db();
            count = dbOperate.ExcSql(cmdText, paras);
            return count;
        }
    }
}
